﻿@using XStudio.WebFramework.Mvc.Extensions
<script type="text/javascript">

    var List = {};
    List.delRoleUrl = "";
    List.editRoleUrl = "";


    List.NameFormatter = function (value, rec, index) {
        var html = "";
        html += "<a  href='" + $("#editRoleUrl").val() + "/" + rec.UID + "' onclick='List.Edit(this); return false;' >" + value + "</a>";
        return html;
    }

    List.DeleteFormatter = function (value, rec, index) {
        if (rec.StateID == 1)
            return "";
        return "<a  class='btn-del' href='" + List.delRoleUrl + "/" + rec.UID + "' onclick='List.Delete(this); return false;' >删除</a>";
    }

    List.EditFormatter = function (value, rec, index) {
        return "<a  class='btn-edit' href='" + $("#editRoleUrl").val() + "/" + rec.UID + "' onclick='List.Edit(this); return false;' >修改</a>";
    }

    List.RoleUserFormatter = function (value, rec, index) {
        return "<a  class='btn-user' href='" + $("#roleUserListUrl").val() + "/" + rec.UID + "' onclick='List.ShowRoleUser(this); return false;' >查看拥有此角色的用户</a>";
    }

    List.StateFormatter = function (value, rec, index) {
        return value == 1 ? "启用" : "禁用";
    }

    List.Delete = function (e) {
        if (!confirm("确认要删除吗？"))
            return;
        $.post($(e).attr("href"), function (data) {
            if (data.IsOK) {
                $('#tbRoleList').datagrid('reload');
            }
            else
                alert(data.Description);
        });
    }

    List.Edit = function (e) {
        var title = "修改" + $(e).parents("tr").find("[field='RoleName']").text();
        Common.ShowTab(e, title);
    }

    List.ShowRoleUser = function (e) {
        var title = $(e).parents("tr").find("[field='RoleName']").text() + "用户列表";
        Common.ShowTab(e, title);
    }

    $(document).ready(function () {
        var lastIndex;

        List.delRoleUrl = $("#delRoleUrl").val();
        List.EditlUrl = $("#editRoleUrl").val();
        $('#tbRoleList').datagrid({ pagination: true });
    });

</script>
@Html.Hidden("roleUserListUrl", Url.Action("RoleUserList"))
@Html.Hidden("delRoleUrl", Url.Action("Delete"))
@Html.Hidden("editRoleUrl", Url.Action("Edit"))
<div class="tt-attach">
    <ul class="op">
        <li></li>
    </ul>
</div>
<div style="padding: 5px 10px;">
    <table id="tbRoleList" style="height: auto" striped="true" rownumbers="true" fitColumns="true" title="" iconcls="icon-edit"
     idfield="UID" checkbox="true" url="@Url.Action("ListData")">
        <thead>
            <tr>
                <th field="RoleName" @(Html.Auth("Edit") ? "formatter=List.NameFormatter" : "") width="150">
                    角色名称
                </th>
                <th field="RoleTypeName" width="100" align="center">
                    角色类型
                </th>
                <th field="Remark" width="570">
                    备注
                </th>
                <th field="StateCodeID" formatter="List.StateFormatter" width="60" align="center">
                    状态
                </th>
                <th field="角色用户" width="90" formatter="List.RoleUserFormatter" align="center">
                    用户列表
                </th>
                @if (Html.Auth("Edit"))
                {
                    <th field="修改" width="50" formatter="List.EditFormatter" align="center">
                        修改
                    </th>
                }
                @if (Html.Auth("Delete"))
                {
                    <th field="删除" width="50" formatter="List.DeleteFormatter" align="center">
                        删除
                    </th>
                }
            </tr>
        </thead>
    </table>
</div>
